﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    mc:Ignorable="d">

    <!-- Resource dictionary entries should be defined here. -->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Colors.xaml"/>
        <ResourceDictionary Source="CalendarStyle.xaml"/>
        <ResourceDictionary Source="ValidationToolTipTemplate.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="DatePickerCalendarStyle" TargetType="{x:Type Calendar}" BasedOn="{StaticResource {x:Type Calendar}}" />

    <Style TargetType="{x:Type DatePicker}">
        <Setter Property="IsTodayHighlighted" Value="True" />
        <Setter Property="SelectedDateFormat" Value="Short" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <!--Set CalendarStyle to DatePickerCalendarStyle.-->
        <Setter Property="CalendarStyle" Value="{DynamicResource DatePickerCalendarStyle}" />
        <Setter Property="Template" Value="{DynamicResource DatePickerTemplate}"/>
    </Style>

    <!--The template for the button that displays the calendar.-->
    <Style x:Key="DropDownButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Template" Value="{DynamicResource DropDownButtonTemplate}"/>
    </Style>

    <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
        <Grid>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualStateGroup.Transitions>
                        <VisualTransition From="Pressed" GeneratedDuration="0:0:0.2" To="MouseOver"/>
                        <VisualTransition From="MouseOver" GeneratedDuration="0:0:0.2" To="Pressed"/>
                        <VisualTransition From="MouseOver" GeneratedDuration="0:0:0.2" To="Normal"/>
                        <VisualTransition From="Normal" GeneratedDuration="0:0:0.2" To="MouseOver"/>
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
                                <EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_DataPickerButton_Blue_Background}"/>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Pressed">
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" Storyboard.TargetName="BackgroundGradient">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0.002"/>
                            </DoubleAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
                                <EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_DataPickerButton_Blue_Background}"/>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled" />
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid FlowDirection="LeftToRight" HorizontalAlignment="Center" Height="18" Margin="0" VerticalAlignment="Center" Width="19">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20*" />
                    <ColumnDefinition Width="20*" />
                    <ColumnDefinition Width="20*" />
                    <ColumnDefinition Width="20*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="23*" />
                    <RowDefinition Height="19*" />
                    <RowDefinition Height="19*" />
                    <RowDefinition Height="19*" />
                </Grid.RowDefinitions>
                <Border x:Name="BackgroundGradient" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius=".5" Margin="0,-1,0,0" Opacity="1" Grid.Row="1" Grid.RowSpan="3">
                    <Border.Background>
                        <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
                            <GradientStop Color="#FFFFFFFF" Offset="0" />
                            <GradientStop Color="#F9FFFFFF" Offset="0.375" />
                            <GradientStop Color="#E5FFFFFF" Offset="0.625" />
                            <GradientStop Color="#C6FFFFFF" Offset="1" />
                        </LinearGradientBrush>
                    </Border.Background>
                    <Border.BorderBrush>
                        <SolidColorBrush Color="{StaticResource Application_DataPickerButton_BorderBrush}" />
                    </Border.BorderBrush>
                </Border>
                <Rectangle Grid.ColumnSpan="4" Grid.RowSpan="1" StrokeThickness="1">
                    <Rectangle.Fill>
                        <SolidColorBrush Color="{StaticResource Application_DataPickerButton_Blue_Background}" />
                    </Rectangle.Fill>
                    <Rectangle.Stroke>
                        <SolidColorBrush Color="{StaticResource Application_DataPickerButton_BorderBrush}" />
                    </Rectangle.Stroke>
                </Rectangle>
                <Path Grid.Row="1" Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="4" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Margin="4,3,4,3" Stretch="Fill"
                      Data="M11.426758,8.4305077 L11.749023,8.4305077                              L11.749023,16.331387 L10.674805,16.331387                              L10.674805,10.299648 L9.0742188,11.298672                             L9.0742188,10.294277 C9.4788408,10.090176                              9.9094238,9.8090878 10.365967,9.4510155                              C10.82251,9.0929432 11.176106,8.7527733                              11.426758,8.4305077 z M14.65086,8.4305077                              L18.566387,8.4305077 L18.566387,9.3435936                              L15.671368,9.3435936 L15.671368,11.255703                              C15.936341,11.058764 16.27293,10.960293                              16.681133,10.960293 C17.411602,10.960293                              17.969301,11.178717 18.354229,11.615566                              C18.739157,12.052416 18.931622,12.673672                             18.931622,13.479336 C18.931622,15.452317                              18.052553,16.438808 16.294415,16.438808                             C15.560365,16.438808 14.951641,16.234707                              14.468243,15.826504 L14.881817,14.929531                             C15.368796,15.326992 15.837872,15.525723                              16.289043,15.525723 C17.298809,15.525723                              17.803692,14.895514 17.803692,13.635098                              C17.803692,12.460618 17.305971,11.873379                              16.310528,11.873379 C15.83071,11.873379                              15.399232,12.079271 15.016094,12.491055                             L14.65086,12.238613 z">
                    <Path.Fill>
                        <SolidColorBrush Color="{StaticResource Application_DataPickerButton_Foreground2}"/>
                    </Path.Fill>
                </Path>
                <Ellipse Grid.ColumnSpan="4" HorizontalAlignment="Center" Height="3" StrokeThickness="0" VerticalAlignment="Center" Width="3">
                    <Ellipse.Fill>
                        <SolidColorBrush Color="{StaticResource Application_DataPickerButton_Foreground}"/>
                    </Ellipse.Fill>
                </Ellipse>
                <Border x:Name="DisabledVisual" Grid.ColumnSpan="4" CornerRadius="0" Opacity="0" Grid.Row="0" Grid.RowSpan="4">
                    <Border.Background>
                        <SolidColorBrush Color="{StaticResource Application_DataPickerButton_Background_Disabled}"/>
                    </Border.Background>
                </Border>
            </Grid>
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="DatePickerTemplate" TargetType="{x:Type DatePicker}">

        <Grid x:Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Height="22">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal"/>
                    <VisualState x:Name="Disabled">
                    	<Storyboard>
                    		<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_DisabledVisual">
                    			<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    		</DoubleAnimationUsingKeyFrames>
                    	</Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="ValidationStates">
                    <VisualState x:Name="Valid">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="InvalidFocused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToolTip.IsOpen)" Storyboard.TargetName="validationTooltip">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <sys:Boolean>true</sys:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="InvalidUnfocused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="2" BorderThickness="1">
                <Border.BorderBrush>
                    <SolidColorBrush Color="{StaticResource Application_DataPicker_BorderBrush}"/>
                </Border.BorderBrush>
                <Border.Background>
                    <SolidColorBrush Color="{StaticResource Application_DataPicker_Background}"/>
                </Border.Background>
            </Border>
            <Button x:Name="PART_Button" Grid.Column="1" HorizontalAlignment="Center" Margin="3,0,3,0" Grid.Row="0" Style="{StaticResource DropDownButtonStyle}" VerticalAlignment="Center" />
            <DatePickerTextBox x:Name="PART_TextBox" Grid.Column="0" HorizontalContentAlignment="Stretch" Grid.Row="0" VerticalContentAlignment="Stretch" Margin="2">
                <DatePickerTextBox.Foreground>
                    <SolidColorBrush Color="{StaticResource Application_DataPicker_Foreground}"/>
                </DatePickerTextBox.Foreground>
                <DatePickerTextBox.CaretBrush>
                    <SolidColorBrush Color="{StaticResource Application_DataPicker_Foreground}"/>
                </DatePickerTextBox.CaretBrush>
                <DatePickerTextBox.BorderBrush>
                    <SolidColorBrush Color="{StaticResource Application_DataPicker_BorderBrush}"/>
                </DatePickerTextBox.BorderBrush>
                <DatePickerTextBox.Background>
                    <SolidColorBrush Color="{StaticResource Application_DataPicker_Background}"/>
                </DatePickerTextBox.Background>
                <DatePickerTextBox.Template>
                    <ControlTemplate TargetType="{x:Type DatePickerTextBox}">
                        <Border x:Name="PART_ContentHost" Background="{TemplateBinding Background}" />
                    </ControlTemplate>
                </DatePickerTextBox.Template>
            </DatePickerTextBox>
            <Border x:Name="ValidationErrorElement" BorderThickness="1" Margin="0" CornerRadius="2" Visibility="Collapsed" IsHitTestVisible="True" Grid.ColumnSpan="2">
                <Border.BorderBrush>
                    <SolidColorBrush Color="{StaticResource Application_TextBox_BorderBrush_ValidationError}"/>
                </Border.BorderBrush>
                <ToolTipService.ToolTip>
                    <ToolTip x:Name="validationTooltip" Placement="Bottom"
						    Template="{DynamicResource ValidationToolTipTemplate}"
    					    PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
    					    DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                    </ToolTip>
                </ToolTipService.ToolTip>
            </Border>
            <Rectangle x:Name="PART_DisabledVisual" Grid.Column="0" Grid.ColumnSpan="2" RadiusY="2" Grid.Row="0" RadiusX="2" Visibility="Visible" Opacity="0"
                       IsHitTestVisible="False">
                <Rectangle.Fill>
                    <SolidColorBrush Color="{StaticResource Application_DataPicker_Background_Disabled}"/>
                </Rectangle.Fill>
            </Rectangle>
            <Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False" />
        </Grid>
    </ControlTemplate>
</ResourceDictionary>